package com.ruoyi.project.survey.controller;


import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.survey.domain.entity.Question;
import com.ruoyi.project.survey.domain.param.QuestionAdd;
import com.ruoyi.project.survey.domain.param.QuestionQuery;
import com.ruoyi.project.survey.service.QuestionService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/question/")
@Api(tags = "问卷")
@RequiredArgsConstructor
public class QuestionController extends BaseController {
    private final QuestionService service;

    @PostMapping("save")
    public AjaxResult save(@RequestBody QuestionAdd add) {
        return service.save(add);
    }

    @PostMapping("update")
    public AjaxResult update(@RequestBody Question question) {
        return service.update(question);
    }

    @PostMapping("delete/{quetionIds}")
    public AjaxResult delete(@PathVariable Long[] quetionIds) {
        return service.delete(quetionIds);
    }

    @PostMapping("deletebatch")
    public AjaxResult deleteBatch(@RequestBody List<Integer> ids) {
        return service.deleteBatch(ids);
    }

    @GetMapping("page")
    public TableDataInfo queryPage(QuestionQuery query) {
        startPage();
        return getDataTable(service.queryPage(query));
    }

    @PostMapping("upload")
    public AjaxResult upload(@RequestPart MultipartFile file) throws IOException {
        return service.upload(file);
    }

}